<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>



<c:if test="${pageContext.request.method=='POST'}">
  <c:choose>
    <c:when test="${param.uid==''}">
      <h3><fmt:message key="reg.needlogin" bundle="${lang}"/></h3>
    </c:when>

    <c:when test="${param.pwd==''}">
      <h3><fmt:message key="reg.needpw" bundle="${lang}"/></h3>
    </c:when>

    <c:when test="${param.pwd!=param.pwd2}">
      <h3><fmt:message key="reg.badpw" bundle="${lang}"/></h3>
    </c:when>

    <c:otherwise>
      <sql:query var="users" dataSource="${dataSource}">
      select c_uid from t_users where c_uid = ? 
      <sql:param value="${param.uid}" />
      </sql:query>

      <c:choose>
        <c:when test="${users.rowCount>0}">
          <h3>Someone already has that user id.</h3>
        </c:when>

        <c:otherwise>
          <sql:update var="users" dataSource="${dataSource}">insert
          into t_users(c_uid,c_pwd,c_accesses,c_first,c_last,c_bad,c_posted,c_type) values (?,?,0,NOW(),NOW(),0,0,'G') 
          <sql:param value="${param.uid}" />

          <sql:param value="${param.pwd}" />

          </sql:update>

          <c:set var="userID" value="${param.uid}"
          scope="session" />

          <c:set var="userType" value="G" scope="session" />

          <c:redirect url="welcome.jsp" />
        </c:otherwise>
      </c:choose>
    </c:otherwise>
  </c:choose>
</c:if>

<html>
  <head>
    <title><fmt:message key="word.register" bundle="${lang}"/></title>
  </head>

  <body>
    <p>
    <fmt:message key="reg.thanks" bundle="${lang}"/>
    </p>
    <form method="POST">
      <table border="1" cellpadding="0" cellspacing="0"
      style="border-collapse: collapse" bordercolor="#111111"
      width="49%" id="AutoNumber1">
        <tr>
          <td width="100%" colspan="2" bgcolor="#0000FF">
            <p align="center">
              <b>
                <font color="#FFFFFF" size="4">
                <fmt:message key="word.register" bundle="${lang}"/></font>
              </b>
            </p>
          </td>
        </tr>

        <tr>
          <td width="26%"><fmt:message key="login.name" bundle="${lang}"/></td>

          <td width="74%">
            <input type="text" name="uid" size="20" />
          </td>
        </tr>

        <tr>
          <td width="26%"><fmt:message key="word.password" bundle="${lang}"/></td>

          <td width="74%">
            <input type="password" name="pwd" size="20" />
          </td>
        </tr>

        <tr>
          <td width="26%"><fmt:message key="reg.verify" bundle="${lang}"/></td>

          <td width="74%">
            <input type="password" name="pwd2" size="20" />
          </td>
        </tr>

        <tr>
          <td width="100%" colspan="2">
            <p align="center">
              <input type="submit" value="<fmt:message key="button.ok" bundle="${lang}"/>" name="OK" />
            </p>
          </td>
        </tr>
      </table>

      <p>&#160;</p>
    </form>

    <p>&#160;</p>
  </body>
</html>

